package com.vastcom.sigma.admin.action;

import com.google.gson.Gson;
import com.vastcom.sigma.admin.model.Searchlog;
import com.vastcom.sigma.admin.service.BlockAdminService;
import com.vastcom.sigma.admin.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@CrossOrigin
@RestController
@PreAuthorize("hasAuthority('admin')")
@RequestMapping("/manage")
public class ManageActioin {

    @Autowired
    private ManageService manageService;


    @Autowired
    private BlockAdminService blockAdminService;

    @PostMapping("saveSearchLog")
    @ResponseBody
    public HashMap saveSearchLog(@RequestBody Searchlog searchlog){
        HashMap hashMap = new HashMap();

        try {
            Searchlog searchlog1 = manageService.saveSearchlog(searchlog);

            String key = searchlog1.getId();
            String jsonStr = "";
            jsonStr = new Gson().toJson(searchlog1);

            boolean flag = blockAdminService.invokeByJson(key, jsonStr);


            hashMap.put("msg","ok");
        } catch (Exception e) {
            hashMap.put("msg","error");
            e.printStackTrace();
        }

        return hashMap;
    }
}
